#include "app.h"

void savestate_mem(struct SMS_SAVESTATE *s)
{
	memset(s,0,sizeof(struct SMS_SAVESTATE));
	
	s->drsms_vdp_line=drsms.vdp_line;
	s->drsms_lines_per_frame=drsms.lines_per_frame;
	s->drsms_vdp_addr=drsms.vdp_addr;
	s->drsms_map_addr=drsms.map_addr;
	s->drsms_sprite_addr=drsms.sprite_addr;
	s->drsms_sprite_tiles=drsms.sprite_tiles;
	s->drsms_vdp_reg0=drsms.vdp_reg0;
	s->drsms_vdp_reg1=drsms.vdp_reg1;
	s->drsms_vdp_reg2=drsms.vdp_reg2;
	s->drsms_vdp_reg3=drsms.vdp_reg3;
	s->drsms_vdp_reg4=drsms.vdp_reg4;
	s->drsms_vdp_reg5=drsms.vdp_reg5;
	s->drsms_vdp_reg6=drsms.vdp_reg6;
	s->drsms_vdp_reg7=drsms.vdp_reg7;
	s->drsms_vdp_reg8=drsms.vdp_reg8;
	s->drsms_vdp_reg9=drsms.vdp_reg9;
	s->drsms_vdp_regA=drsms.vdp_regA;
	s->drsms_vdp_regB=drsms.vdp_regB;
	s->drsms_vdp_regC=drsms.vdp_regC;
	s->drsms_vdp_regD=drsms.vdp_regD;
	s->drsms_vdp_regE=drsms.vdp_regE;
	s->drsms_vdp_regF=drsms.vdp_regF;
	s->drsms_vdp_status=drsms.vdp_status;
	s->drsms_vdp_left=drsms.vdp_left;
	s->drsms_cram_gg_latch=drsms.cram_gg_latch;
	s->drsms_vdp_pending=drsms.vdp_pending;
	s->drsms_vdp_type=drsms.vdp_type;
	s->drsms_first_byte=drsms.first_byte;
	s->drsms_vdp_buffer=drsms.vdp_buffer;
	s->drsms_max_rom_pages=drsms.max_rom_pages;
	s->drsms_memory_reg_C=drsms.memory_reg_C;
	s->drsms_memory_reg_D=drsms.memory_reg_D;
	s->drsms_memory_reg_E=drsms.memory_reg_E;
	s->drsms_memory_reg_F=drsms.memory_reg_F;
	s->drsms_drsms_country=drsms.drsms_country;
	s->drsms_sms_port0=drsms.sms_port0;
	s->drsms_sms_port1=drsms.sms_port1;
	s->drsms_sms_port5=drsms.sms_port5;
	s->drsms_sms_port63=drsms.sms_port63;
	s->drsms_gg_mode=drsms.gg_mode;
	s->drz80_Z80PC=drz80.Z80PC;
	s->drz80_Z80A=drz80.Z80A;
	s->drz80_Z80F=drz80.Z80F;
	s->drz80_Z80BC=drz80.Z80BC;
	s->drz80_Z80DE=drz80.Z80DE;
	s->drz80_Z80HL=drz80.Z80HL; 
	s->drz80_Z80SP=drz80.Z80SP;
	s->drz80_Z80PC_BASE=drz80.Z80PC_BASE;
	s->drz80_Z80SP_BASE=drz80.Z80SP_BASE;
	s->drz80_Z80IX=drz80.Z80IX;
	s->drz80_Z80IY=drz80.Z80IY;
	s->drz80_Z80I=drz80.Z80I;
	s->drz80_Z80A2=drz80.Z80A2;
	s->drz80_Z80F2=drz80.Z80F2;
	s->drz80_Z80BC2=drz80.Z80BC2;
	s->drz80_Z80DE2=drz80.Z80DE2;
	s->drz80_Z80HL2=drz80.Z80HL2;   
	s->drz80_Z80_IRQ=drz80.Z80_IRQ;
	s->drz80_Z80IF=drz80.Z80IF;
	s->drz80_Z80IM=drz80.Z80IM;
	s->drz80_Z80R=drz80.Z80R;
	s->drz80_z80irqvector=drz80.z80irqvector;
	memcpy(&s->work_ram,work_ram,0x2000);
	memcpy(&s->vram,vram,0x4000);
	memcpy(&s->cram,cram,0x80);
	memcpy(&s->sram,sram,0x8000);
	memcpy(&s->PSG,&PSG,sizeof(PSG));
	s->drz80_Z80_NMI=drz80.Z80_NMI;
}

void loadstate_mem(const struct SMS_SAVESTATE *s)
{
	int x=0,y=0;
	unsigned int old_DT_Table;

	drsms.vdp_line=s->drsms_vdp_line;
	drsms.lines_per_frame=s->drsms_lines_per_frame;
	drsms.vdp_addr=s->drsms_vdp_addr;
	drsms.map_addr=s->drsms_map_addr;
	drsms.sprite_addr=s->drsms_sprite_addr;
	drsms.sprite_tiles=s->drsms_sprite_tiles;
	drsms.vdp_reg0=s->drsms_vdp_reg0;
	drsms.vdp_reg1=s->drsms_vdp_reg1;
	drsms.vdp_reg2=s->drsms_vdp_reg2;
	drsms.vdp_reg3=s->drsms_vdp_reg3;
	drsms.vdp_reg4=s->drsms_vdp_reg4;
	drsms.vdp_reg5=s->drsms_vdp_reg5;
	drsms.vdp_reg6=s->drsms_vdp_reg6;
	drsms.vdp_reg7=s->drsms_vdp_reg7;
	drsms.vdp_reg8=s->drsms_vdp_reg8;
	drsms.vdp_reg9=s->drsms_vdp_reg9;
	drsms.vdp_regA=s->drsms_vdp_regA;
	drsms.vdp_regB=s->drsms_vdp_regB;
	drsms.vdp_regC=s->drsms_vdp_regC;
	drsms.vdp_regD=s->drsms_vdp_regD;
	drsms.vdp_regE=s->drsms_vdp_regE;
	drsms.vdp_regF=s->drsms_vdp_regF;
	drsms.vdp_status=s->drsms_vdp_status;
	drsms.vdp_left=s->drsms_vdp_left;
	drsms.cram_gg_latch=s->drsms_cram_gg_latch;
	drsms.vdp_pending=s->drsms_vdp_pending;
	drsms.vdp_type=s->drsms_vdp_type;
	drsms.first_byte=s->drsms_first_byte;
	drsms.vdp_buffer=s->drsms_vdp_buffer;
	drsms.max_rom_pages=s->drsms_max_rom_pages;
	drsms.memory_reg_C=s->drsms_memory_reg_C;
	drsms.memory_reg_D=s->drsms_memory_reg_D;
	drsms.memory_reg_E=s->drsms_memory_reg_E;
	drsms.memory_reg_F=s->drsms_memory_reg_F;
	drsms.drsms_country=s->drsms_drsms_country;
	drsms.sms_port0=s->drsms_sms_port0;
	drsms.sms_port1=s->drsms_sms_port1;
	drsms.sms_port5=s->drsms_sms_port5;
	drsms.sms_port63=s->drsms_sms_port63;
	drsms.gg_mode=s->drsms_gg_mode;
	drz80.Z80PC=s->drz80_Z80PC;
	drz80.Z80A=s->drz80_Z80A;
	drz80.Z80F=s->drz80_Z80F;
	drz80.Z80BC=s->drz80_Z80BC;
	drz80.Z80DE=s->drz80_Z80DE;
	drz80.Z80HL=s->drz80_Z80HL; 
	drz80.Z80SP=s->drz80_Z80SP;
	drz80.Z80PC_BASE=s->drz80_Z80PC_BASE;
	drz80.Z80SP_BASE=s->drz80_Z80SP_BASE;
	drz80.Z80IX=s->drz80_Z80IX;
	drz80.Z80IY=s->drz80_Z80IY;
	drz80.Z80I=s->drz80_Z80I;
	drz80.Z80A2=s->drz80_Z80A2;
	drz80.Z80F2=s->drz80_Z80F2;
	drz80.Z80BC2=s->drz80_Z80BC2;
	drz80.Z80DE2=s->drz80_Z80DE2;
	drz80.Z80HL2=s->drz80_Z80HL2;   
	drz80.Z80_IRQ=s->drz80_Z80_IRQ;
	drz80.Z80IF=s->drz80_Z80IF;
	drz80.Z80IM=s->drz80_Z80IM;
	drz80.Z80R=s->drz80_Z80R;
	drz80.z80irqvector=s->drz80_z80irqvector;
	memcpy(&work_ram,&s->work_ram,0x2000);
	memcpy(&vram,&s->vram,0x4000);
	memcpy(&cram,&s->cram,0x80);
	memcpy(&sram,&s->sram,0x8000);
	memcpy(&PSG,&s->PSG,sizeof(PSG));
	drz80.Z80_NMI=s->drz80_Z80_NMI;
}


